﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using WeifenLuo.WinFormsUI.Docking;
using System.Text;
using System.Windows.Forms;
using ArcEngine.Resources;

namespace ArcEngine.Editor
{
	public partial class StringTableForm : DockContent
	{
		/// <summary>
		/// 
		/// </summary>
		public StringTableForm()
		{
			InitializeComponent();
		}


		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public bool Init(StringTable handle)
		{
			stringTable = handle;
			TabText = handle.Name;


			RebuildGridView();

			return true;
		}


		/// <summary>
		/// Regenerates the GridView
		/// </summary>
		private void RebuildGridView()
		{
			GridView.Rows.Clear();


			string[] keys = stringTable.GetStrings();
			foreach (string key in keys)
			{
				int id = GridView.Rows.Add();

				GridView.Rows[id].Cells["Key"].Value = key;
				GridView.Rows[id].Cells["Value"].Value = stringTable.GetString(key);

			}
		}



		#region Variables
		/// <summary>
		/// 
		/// </summary>
		StringTable stringTable;

		#endregion

		#region Events

		/// <summary>
		/// OnRowValidating
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnRowValidating(object sender, DataGridViewCellCancelEventArgs e)
		{
			stringTable.Add((string )GridView.Rows[e.RowIndex].Cells[0].Value,
							(string )GridView.Rows[e.RowIndex].Cells[1].Value);
		}

		#endregion
	}
}
